<?php
/**
 * @author  HID丨emotion
 * @license http://www.hiders.cn
 * @version 2019/1/22 18:21
 */

namespace hiders\common;

class Random
{
    public static function getString($length = 16)
    {
        $chars        = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $chars_length = strlen($chars) - 1;
        $str          = "";
        for ($i = 0; $i < $length; $i++) {
            $str .= substr($chars, mt_rand(0, $chars_length), 1);
        }

        return $str;
    }

    public static function getNumberString($length = 8)
    {
        $str = "";
        for ($i = 0; $i < $length; $i++) {
            $str .= rand(0, 9);
        }

        return $str;
    }

    public static function getNumber($min = 0, $max = 9)
    {
        return rand($min, $max);
    }

    public static function getOne(&$data)
    {
        $max = count($data);
        if ($max) {
            return $data[ self::getNumber(0, $max - 1) ];
        } else {
            return '';
        }
    }

    public static function getId()
    {
        return uniqid('', true);
    }

    public static function getIp()
    {
        $ip_long  = array(
            array('607649792', '608174079'), //36.56.0.0-36.63.255.255
            array('975044608', '977272831'), //58.30.0.0-58.63.255.255
            array('999751680', '999784447'), //59.151.0.0-59.151.127.255
            array('1019346944', '1019478015'), //60.194.0.0-60.195.255.255
            array('1038614528', '1039007743'), //61.232.0.0-61.237.255.255
            array('1783627776', '1784676351'), //106.80.0.0-106.95.255.255
            array('1947009024', '1947074559'), //116.13.0.0-116.13.255.255
            array('1987051520', '1988034559'), //118.112.0.0-118.126.255.255
            array('2035023872', '2035154943'), //121.76.0.0-121.77.255.255
            array('2078801920', '2079064063'), //123.232.0.0-123.235.255.255
            array('-1950089216', '-1948778497'), //139.196.0.0-139.215.255.255
            array('-1425539072', '-1425014785'), //171.8.0.0-171.15.255.255
            array('-1236271104', '-1235419137'), //182.80.0.0-182.92.255.255
            array('-770113536', '-768606209'), //210.25.0.0-210.47.255.255
            array('-569376768', '-564133889'), //222.16.0.0-222.95.255.255
        );
        $rand_key = mt_rand(0, 14);

        return long2ip(mt_rand($ip_long[ $rand_key ][0], $ip_long[ $rand_key ][1]));
    }

    public static function getPeopleName()
    {
        $xing = '赵钱孙李周吴郑王冯陈沈韩杨朱秦许何吕张孔曹严魏陶姜谢邹窦章苏潘范彭鲁马方任袁鲍史唐薛雷贺倪殷罗毕郝安常卞齐顾孟黄尹姚邵汪祁毛狄伏成戴宋茅庞纪舒项祝董梁杜阮季贾江童颜郭梅林钟徐邱骆高夏蔡田樊胡万卢莫柯应丁邓单洪包石崔吉龚程邢裴陆荀于宁刘景龙叶黎乔党申庄柴阎连习古易廖文寇师巩聂关荆';
        $ming = '伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝丽阳妮宝贝初程梵罡恒鸿桦骅剑娇纪宽苛灵玛媚琪晴容睿烁堂唯威韦雯苇萱阅彦宇雨洋忠宗曼紫逸贤蝶菡绿蓝儿翠烟';

        $mingCount = mb_strlen($ming) - 1;

        $name = mb_substr($xing, mt_rand(0, mb_strlen($xing) - 1), 1) . mb_substr($ming, mt_rand(0, $mingCount), 1);

        if (rand(0, 1)) {
            $name .= mb_substr($ming, mt_rand(0, $mingCount), 1);
        }

        return $name;
    }
}